package com.example.home.government.acivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.government.adapter.AppealMainAdapter;
import com.example.home.government.bean.DetailsBean;
import com.example.home.tool.OKHttpTool;

public class AppealMainActivity extends AppCompatActivity {

    private String listId;
    private TextView title;
    private RecyclerView rcv_list;
    private String name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appeal_main);
        Intent intent = getIntent();
        listId = intent.getStringExtra("appeal_id");
        name = intent.getStringExtra("title");

        initView();

        getData();
    }



    private void getData() {
        OKHttpTool.doNetRequest("prod-api/api/gov-service-hotline/appeal/list?appealCategoryId=" + listId + "&page" + "Num=1&pageSize=10",
                OKHttpTool.GET,
                DetailsBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        DetailsBean detailsBean = (DetailsBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                title.setText(name);
                                bindAppeal(detailsBean);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void bindAppeal(DetailsBean detailsBean) {
        AppealMainAdapter appealMainAdapter = new AppealMainAdapter(AppealMainActivity.this, detailsBean.getRows());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(AppealMainActivity.this);
        rcv_list.setAdapter(appealMainAdapter);
        rcv_list.setLayoutManager(linearLayoutManager);
    }


    private void initView() {
        ImageView back = findViewById(R.id.back);
        title = findViewById(R.id.title);
        Button btn_send = findViewById(R.id.btn_send);
        btn_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AppealMainActivity.this, SendAppeal.class);
                intent.putExtra("listId",listId);
                startActivity(intent);
            }
        });
        rcv_list = findViewById(R.id.rcv_list);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppealMainActivity.this.finish();
            }
        });
    }
}